package com.pubinfo.passbook.api.controller.rule;

import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.entity.TRuleRole;
import com.pubinfo.passbook.common.model.dto.rule.RuleRole;
import com.pubinfo.passbook.common.model.dto.rule.RuleRoleParam;
import com.pubinfo.passbook.common.model.http.eip.UserInfo;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TRuleRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("rule/role/manager")
@Api(tags = "规则角色管理")
public class TRuleRoleController {
  
  @Resource
  private TRuleRoleService roleService;
  @Autowired
  UserInfoService userInfoService;
  
  @PostMapping("save")
  @ApiModelProperty("新增规则角色")
  public JsonResult<Boolean> saveRuleRole(@RequestBody RuleRole role) {
    UserInfo userInfo = userInfoService.getCurrentUserInfo();
    return JsonResult.success(roleService.saveRuleRole(role, userInfo, userInfoService.getRoleInfo()));
  }
  
  @DeleteMapping("remove")
  @ApiModelProperty("删除规则角色")
  public JsonResult<String> removeRuleRole(String id) {
    UserInfo userInfo = userInfoService.getCurrentUserInfo();
    return roleService.deleteRuleRole(id, userInfo, userInfoService.getRoleInfo());
  }
  
  @PostMapping("select")
  @ApiModelProperty("查找规则角色")
  public JsonResult<MyPage<TRuleRole>> selectRuleRole(@RequestBody RuleRoleParam param) {
    UserInfo userInfo = userInfoService.getCurrentUserInfo();
    return JsonResult.success(new MyPage<>(roleService.selectRuleRole(param, userInfo, userInfoService.getRoleInfo())));
  }
  
  @PostMapping("update")
  @ApiModelProperty("更新规则角色")
  public JsonResult<String> updateRuleRole(@RequestBody RuleRole role) {
    UserInfo userInfo = userInfoService.getCurrentUserInfo();
    return roleService.updateRuleRole(role, userInfo, userInfoService.getRoleInfo());
  }
}
